from rest_framework import serializers

from .models import Nav,Category,Banner,Fx,Cate,Categorys,CategoryGoods


# 导航栏
class NavModelSerializer(serializers.ModelSerializer):
    """
    导航菜单的序列化器
    """
    class Meta:
        model = Nav
        fields = ["name", "link", "is_http"]

# 子菜单的序列器类
class ChildrenSerializer(serializers.ModelSerializer):
    class Meta:
        model=Category
        fields=['id','cname']
# 首页分类
class CategorySerializer(serializers.ModelSerializer):
    children=ChildrenSerializer(many=True)
    class Meta:
        model = Category
        fields = '__all__'

class BannerSerializer(serializers.ModelSerializer):
    class Meta:
        model = Banner
        fields = ['image','is_http','link']
class FxSerializer(serializers.ModelSerializer):
    class Meta:
        model = Fx
        fields = ['image','description','name']

class CateSerializer(serializers.ModelSerializer):
    class Meta:
        model = Cate
        fields = ['image']
class CategorysSerializer(serializers.ModelSerializer):
    class Meta:
        model = Categorys
        fields = ['name','id']
class CategoryGoodsSerializer(serializers.ModelSerializer):
    class Meta:
        model = CategoryGoods
        fields = ['description','image','price','number','jb']